package com.sinaapp.mspring.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.sinaapp.mspring.dao.SysLogMapper;
import com.sinaapp.mspring.pojo.SysLog;
import com.sinaapp.mspring.service.SysLogServiceI;

@Service
public class SysLogServiceImpl implements SysLogServiceI {

	@Autowired
	private SysLogMapper sysLogDao;
	
	@Override
	public void log(SysLog log) {
		// TODO Auto-generated method stub
		sysLogDao.insert(log);
	}

	@Override
	public String loginUserIp() {
		// TODO Auto-generated method stub
		HttpServletRequest request;
		try {
			request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
			return request.getRemoteAddr();
		} catch (Exception e) {
			return "未知";
		}    
	}

}
